package com.boot.mall.product.service.impl;

import com.boot.mall.product.vo.Images;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.boot.common.utils.PageUtils;
import com.boot.common.utils.Query;

import com.boot.mall.product.dao.SkuImagesDao;
import com.boot.mall.product.entity.SkuImagesEntity;
import com.boot.mall.product.service.SkuImagesService;


@Service("skuImagesService")
public class SkuImagesServiceImpl extends ServiceImpl<SkuImagesDao, SkuImagesEntity> implements SkuImagesService {


    @Override
    public void saveSkuImages(List<Images> skuImages, Long skuId) {
        List<SkuImagesEntity> list = new ArrayList<>();
        //遍历图片信息保存
        for (Images skuImage : skuImages) {
            SkuImagesEntity imagesEntity = new SkuImagesEntity();
            imagesEntity.setImgSort(0);
            imagesEntity.setImgUrl(skuImage.getImgUrl());
            imagesEntity.setSkuId(skuId);
            imagesEntity.setDefaultImg(skuImage.getDefaultImg());
            list.add(imagesEntity);
        }
        //批量保存
        this.saveBatch(list);
    }

    @Override
    public List<SkuImagesEntity> getSkuImagesBySkuId(Long skuId) {
        List<SkuImagesEntity> imagesEntities = this.list(new QueryWrapper<SkuImagesEntity>().eq("sku_id", skuId));
        return imagesEntities;
    }
}